home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / mssghkct / systray.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-11-20  |  5.2 KB  |  167 lines

  1. VERSION 4.00
  2. Begin VB.Form frmSysTray 
  3.    BorderStyle     =   4  'Fixed ToolWindow
  4.    Caption         =   "SysTray"
  5.    ClientHeight    =   2385
  6.    ClientLeft      =   2820
  7.    ClientTop       =   3555
  8.    ClientWidth     =   4110
  9.    Height          =   2790
  10.    Icon            =   "SysTray.frx":0000
  11.    Left            =   2760
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   2385
  16.    ScaleWidth      =   4110
  17.    ShowInTaskbar   =   0   'False
  18.    Top             =   3210
  19.    Width           =   4230
  20.    Begin VB.Label Label2 
  21.       BackStyle       =   0  'Transparent
  22.       Caption         =   "Copyright 
  23.  1998, Alex Wainstein"
  24.       Height          =   240
  25.       Left            =   60
  26.       TabIndex        =   3
  27.       Top             =   810
  28.       Width           =   3210
  29.    End
  30.    Begin VB.Label lblMailTo 
  31.       BackStyle       =   0  'Transparent
  32.       Caption         =   "alexw@netvision.net.il"
  33.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  34.          Name            =   "MS Sans Serif"
  35.          Size            =   8.25
  36.          Charset         =   177
  37.          Weight          =   400
  38.          Underline       =   -1  'True
  39.          Italic          =   0   'False
  40.          Strikethrough   =   0   'False
  41.       EndProperty
  42.       ForeColor       =   &H8000000D&
  43.       Height          =   240
  44.       Left            =   645
  45.       MouseIcon       =   "SysTray.frx":014A
  46.       MousePointer    =   99  'Custom
  47.       TabIndex        =   2
  48.       Top             =   1080
  49.       Width           =   1875
  50.    End
  51.    Begin VB.Label Label4 
  52.       BackStyle       =   0  'Transparent
  53.       Caption         =   "e-mail:"
  54.       Height          =   210
  55.       Left            =   75
  56.       TabIndex        =   1
  57.       Top             =   1080
  58.       Width           =   510
  59.    End
  60.    Begin VB.Label Label1 
  61.       Caption         =   "This sample uses Message Hook control to create a taskbar tray notification area icon and handle all mouse events."
  62.       Height          =   675
  63.       Left            =   90
  64.       TabIndex        =   0
  65.       Top             =   90
  66.       Width           =   3945
  67.    End
  68.    Begin MSGHOOKLibCtl.MsgHook MsgHook1 
  69.       Left            =   2340
  70.       OleObjectBlob   =   "SysTray.frx":029C
  71.       Top             =   1830
  72.    End
  73.    Begin VB.Menu mnuBar 
  74.       Caption         =   "Menu"
  75.       Visible         =   0   'False
  76.       Begin VB.Menu mnuShow 
  77.          Caption         =   "&Show"
  78.       End
  79.       Begin VB.Menu mnuExit 
  80.          Caption         =   "E&xit"
  81.       End
  82.       Begin VB.Menu mnuSep1 
  83.          Caption         =   "-"
  84.       End
  85.       Begin VB.Menu mnuAbout 
  86.          Caption         =   "&About"
  87.       End
  88.    End
  89. Attribute VB_Name = "frmSysTray"
  90. Attribute VB_Creatable = False
  91. Attribute VB_Exposed = False
  92. Option Explicit
  93. ' See Global.bas for the global declarations
  94. Dim t As NOTIFYICONDATA
  95. Private bExit As Boolean
  96. Private Sub Form_Load()
  97. '1. Add icon to the system tray
  98.     t.cbSize = Len(t)
  99.     t.hwnd = Me.hwnd
  100.     t.uId = 1&
  101.     t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
  102.     t.ucallbackMessage = WM_TRAYNOTIFY
  103.     t.hIcon = Me.Icon
  104.     t.szTip = "Message Hook!" & Chr$(0)
  105.     Shell_NotifyIcon NIM_ADD, t
  106.     App.TaskVisible = False
  107. '2. Set MsgHook to handle WM_TRAYNOTIFY message for this window
  108. MsgHook1.hwnd = hwnd
  109. MsgHook1.AddMessage WM_TRAYNOTIFY, mshEatMessage 'mshPostProcess
  110. End Sub
  111. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  112. ' If closed from system menu or 'x' button - just hide
  113. If UnloadMode = vbFormControlMenu And Not bExit Then
  114.     Cancel = True
  115.     Hide
  116. End If
  117. 'else close
  118. End Sub
  119. Private Sub Form_Unload(Cancel As Integer)
  120.     t.cbSize = Len(t)
  121.     t.hwnd = Me.hwnd
  122.     t.uId = 1&
  123.     t.uFlags = 0&
  124.     Shell_NotifyIcon NIM_DELETE, t
  125. End Sub
  126. Private Sub lblMailTo_Click()
  127. Dim res As Long
  128. Dim lpOperation As String
  129. Dim lpFile As String
  130. Dim lpParameters As String
  131. Dim lpDirectory As String
  132. Dim nShowCmd As Long
  133. lpOperation = "open"
  134. lpFile = "MAILTO:" + lblMailTo
  135. nShowCmd = vbNormalFocus
  136. res = ShellExecute(hwnd, lpOperation, lpFile, lpParameters, ByVal lpDirectory, nShowCmd)
  137. End Sub
  138. Private Sub mnuAbout_Click()
  139.     frmAbout.Show vbModal
  140. End Sub
  141. Private Sub mnuExit_Click()
  142. ' We cannot simply call Unload Me because we need
  143. ' to let Message Hook to complete window message processing
  144. ' BEFORE the window is destroyed, but Unload Me does SendMessage
  145. ' We need to use PostMessage:
  146. bExit = True
  147. PostMessage MsgHook1.hwnd, WM_CLOSE, 0&, 0&
  148. End Sub
  149. Private Sub mnuShow_Click()
  150.     Me.Show
  151. End Sub
  152. Private Sub MsgHook1_Message(ByVal MsgId As Long, ByVal wParam As Long, ByVal lParam As Long, ByVal MsgProcessing As Integer, MsgResult As Long)
  153. Select Case MsgId
  154. Case WM_TRAYNOTIFY:
  155.        Select Case lParam
  156.             Case WM_LBUTTONDBLCLK:
  157.             Case WM_LBUTTONDOWN:
  158.             Case WM_LBUTTONUP:
  159.                     mnuShow_Click
  160.             Case WM_RBUTTONDBLCLK:
  161.             Case WM_RBUTTONDOWN:
  162.             Case WM_RBUTTONUP:
  163.                 PopupMenu mnuBar, , , , mnuShow ' This may invoke mnuExit_Click
  164.         End Select
  165. End Select
  166. End Sub
  167.